<template>
	<el-tree :data="treeData" ref="tree" accordion node-key="id" :default-expanded-keys="expandNodeId" :expand-on-click-node="false" highlight-current :props="defaultProps" @node-click="nodeClick"></el-tree>
</template>
<script>
export default {
	data() {
		return {
			treeData: this.$store.state.accountSubjectStore.treeData,
			expandNodeId: this.$store.state.accountSubjectStore.expandNodeId,
			defaultProps: {
				label: 'name',
                children: 'subAssertList'
			}
		}
	},
	watch: {
		expandNodeId(newVal) {		//设置节点高亮
			this.$nextTick(() => {
				this.$refs.tree.setCurrentKey(this.expandNodeId[0]);			//设置高亮状态
			});
			this.$store.dispatch('accountSubjectStore/getSubjectTableDataById', newVal[0]);
		}
	},
	methods: {
		nodeClick(row) {
			this.$store.commit('accountSubjectStore/updateNode', row);
			this.$store.dispatch('accountSubjectStore/getSubjectTableDataById', row['id']);
		}
	},
	created() {
		this.$store.dispatch('accountSubjectStore/getTreeData');
	}
}
</script>